<?php
require_once('../lib/config.php');
require_once('../lib/whatsit.class.php');

$id = (int)$_GET['id'];

$user = new $whatsit_user_class();
$db = new $whatsit_database_class($user->getUserName());

$whatsit = $db->getWhatsit($id);

$pref_array = $whatsit->getPreferenceArray();

print_r($pref_array);
?>
<html>
<head>
<title>Edit Preferences for <?= $whatsit->getTitle() ?></title>
</head>
<body>
<form>
<table>
<?php foreach ($pref_array as $name=>$p) : ?>
	<tr>
	<?php if ($p['type'] == 'string') : ?>
		<td align="right"><?= $p['display'] ?></td>
		<td><input type="text" name="prefs[<?= $name ?>]" value="<?= $p['value'] ?>"/></td>
	<?php elseif ($p['type'] == 'bool') : ?>
		<td align="right"><?= $p['display'] ?></td>
		<td><input type="checkbox" name="prefs[<?= $name ?>]" <?php if ($p['value'] == true) : ?>CHECKED<?php endif; ?>/></td>
	<?php elseif ($p['type'] == 'enum') : ?>
		<td align="right"><?= $p['display'] ?></td>
		<td><select name="prefs[<?= $name ?>]">
				<?php foreach ($p['options'] as $o) : ?>
					<option value="<?= $o['value'] ?>" <?php if ($p['value'] == $o['value']) echo "SELECTED"; ?>><?= $o['display'] ?></option>
				<?php endforeach; ?>	
			</select>
		</td>
	<?php elseif ($p['type'] == 'hidden') : ?>
		<td align="right"></td>
		<td><input type="hidden" name="prefs[<?= $name ?>]" value="<?= $p['value'] ?>"/></td>	
	<?php endif; ?>
	</tr>
<?php endforeach; ?>
</table>
<input type="Submit" value="Submit"/><input type="button" value="Cancel"/>
</form>
</body>
</html>
